//
//  JZHPengYouContCell.m
//  极致荟
//
//  Created by hetao on 14-5-7.
//  Copyright (c) 2014年 mac. All rights reserved.
//

#import "JZHPengYouContCell.h"
#import "CJBrowseUIImageView.h"
@implementation JZHPengYouContCell

- (void)awakeFromNib
{
    [self addSubview:self.anview];
    self.anview.hidden=YES;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (CGFloat) addCellData:(JZHTheDiary *)td
{
    self.content.text=td.content;
    [self.content  sizeToFit];
    [self addimage:td.images path:td.pathHead];
    [ImageCache imageUrl:td.userHeadImage UiImageview:self.headImage];
    self.name.text=td.name;
    float hige=self.content.frame.origin.y+self.content.frame.size.height+self.addimageView.frame.size.height;
    [self.contentView setFrame:CGRectMake(0, 0, 320, hige+30)];
    if(td.images.count==1)
    {
        return hige+50;

    }else
    {
        return hige+30;

    }
}
- (void)addimage:(NSArray *)arr path:(NSString *)path;
{
    NSMutableArray *muarr=[[NSMutableArray alloc]init];
    NSMutableArray *muview=[[NSMutableArray alloc]init];
    if( arr.count==0)
    {
        [self.addimageView setFrame:CGRectMake(self.addimageView.frame.origin.x, self.content.frame.origin.y+self.content.frame.size.height, self.addimageView.frame.size.width, 0)];
        return;

    }
    int leng=self.addimageView.frame.size.width/arr.count;
    if(arr.count==1)
    {
        
        CJBrowseUIImageView *iview=[[CJBrowseUIImageView alloc]initWithFrame:CGRectMake(80, 0, self.addimageView.frame.size.width-150, self.addimageView.frame.size.height-40)];
        //[iview setImage:[UIImage imageNamed:@"1.jpg"]];
        [ImageCache imageUrl:[path stringByAppendingString:arr[0]] UiImageview:iview];
        [self.addimageView setFrame:CGRectMake(self.addimageView.frame.origin.x, self.content.frame.origin.y+self.content.frame.size.height+10, self.addimageView.frame.size.width, iview.frame.size.height+iview.frame.origin.y)];
        [self.addimageView addSubview:iview];
        [muarr addObject:iview.image];
        [iview showImages:muarr];
        return;
    }else{
        for(int i=0;i<arr.count;i++)
        {
            CJBrowseUIImageView *iview=[[CJBrowseUIImageView alloc]initWithFrame:CGRectMake(i*leng, 0, leng-20, leng-20)];
            [ImageCache imageUrl:[path stringByAppendingString:arr[i]] UiImageview:iview];
            [self.addimageView addSubview:iview];
            [muarr addObject:iview.image];
            [muview addObject:iview];
        }
        for(CJBrowseUIImageView *cj in muview)
        {
            [cj showImages:muarr];
        }
    }
     [self.addimageView setFrame:CGRectMake(self.addimageView.frame.origin.x, self.content.frame.origin.y+self.content.frame.size.height+10, self.addimageView.frame.size.width, leng)];
    
    
//[ImageCache imageUrl:<#(NSString *)#> UiImageview:<#(UIImageView *)#>]
}
- (IBAction)zan:(id)sender

{
    [self showzan:self.anbut];
}
- (IBAction)showzan:(UIButton *)sender
{
    
    CGRect rect=self.anview.frame;
    
    if(sender.selected)
    {
        
        [UIView animateWithDuration:.3 animations:^{
            [self.anview setFrame:CGRectMake(sender.frame.origin.x+rect.size.width, self.anview.frame.origin.y, rect.size.width, rect.size.height)];
        } completion:^(BOOL finished) {
            self.anview.hidden=YES;
            sender.selected=NO;
        }];
        
    }else
    {
        
        [self.anview setFrame:CGRectMake(sender.frame.origin.x, sender.frame.origin.y-3, rect.size.width, rect.size.height)];
        self.anview.hidden=NO;
        [UIView animateWithDuration:.3 animations:^{
            [self.anview setFrame:CGRectMake(sender.frame.origin.x-rect.size.width, self.anview.frame.origin.y, rect.size.width, rect.size.height)];
        } completion:^(BOOL finished) {
            sender.selected=YES;
        }];
    }
    
    
}

- (IBAction)ping:(id)sender
{
    [self showzan:self.anbut];
}

@end
